package com.jiayang.webviewprocess.webviewclient;

import android.graphics.Bitmap;
import android.util.Log;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;

/**
 * @ClassName MyWebViewClient
 * @Author JIAYANG
 * @Date 2022/4/26 15:35
 * @Email 1354856871@qq.com
 */
public class MyWebViewClient extends WebViewClient {

    private static final String TAG = "MyWebViewClient";

    private WebViewCallBack mWebViewCallBack;
    public MyWebViewClient(WebViewCallBack webViewCallBack) {this.mWebViewCallBack = webViewCallBack;
    }

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
        if (mWebViewCallBack!=null){
            Log.d(TAG,"进度条:${}"+view.getProgress());

            mWebViewCallBack.pageStarted(url);
        }else {
            Log.e(TAG,"WebViewCallBack is null.");
        }
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        Log.d(TAG,"进度条:"+view.getProgress());

        if (mWebViewCallBack!=null){
            mWebViewCallBack.pageFinished(view,url);
        }else {
            Log.e(TAG,"WebViewCallBack is null.");
        }
    }

    @Override
    public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
        super.onReceivedError(view, request, error);
        if (mWebViewCallBack!=null){
            mWebViewCallBack.onError();
        }else {
            Log.e(TAG,"WebViewCallBack is null.");
        }
    }
}
